package com.dooioo.fangyou.web;

import com.dooioo.fangyou.entity.PetType;
import com.dooioo.fangyou.service.PetTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * com.dooioo.fangyou.web
 * User: kqy
 * Date: 2010-12-3
 * Time: 11:43:49
 */
public class PetBindingInitializer implements WebBindingInitializer {

    @Autowired
    private PetTypeService petTypeService;

    public void initBinder(WebDataBinder webDataBinder, WebRequest webRequest) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
		webDataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
		webDataBinder.registerCustomEditor(PetType.class, new PetTypeEditor(petTypeService));
    }
}
